package math2;

import math2.FunctionRnToR;
import math2.PolynomialRToR;

import org.junit.Test;
import org.junit.Assert;

public class PolynomialRToRTest {

	@Test
	public void test1() {
		FunctionRnToR p = new PolynomialRToR(1, 1);
		for (int i = 0; i < 10; i++) {
			double x = i / 10;
			Assert.assertEquals(1 + x, p.valueAt(x), 1e-10);
			Assert.assertEquals(1, p.gradientAt(x)[0], 1e-10);
		}
	}

	@Test
	public void test2() {
		FunctionRnToR p = new PolynomialRToR(1, 1);
		FunctionRnToR p2 = new PolynomialRToR(0, 1);
		FunctionRnToR m = p.multiply(1, p2);
		for (int i = 0; i < 10; i++) {
			double x = i / 10;
			Assert.assertEquals((1 + x) * x, m.valueAt(x), 1e-10);
			Assert.assertEquals(1 + 2 * x, m.gradientAt(x)[0], 1e-10);
		}
	}
}
